package test.wechat.handler;

import java.util.Date;

import lodsve.wechat.api.message.MsgHandler;
import lodsve.wechat.beans.message.MsgType;
import lodsve.wechat.beans.message.ReplyType;
import lodsve.wechat.beans.message.receive.msg.TextMsg;
import lodsve.wechat.beans.message.reply.Reply;
import lodsve.wechat.beans.message.reply.TextReply;
import org.springframework.stereotype.Component;

/**
 * .
 *
 * @author sunhao(sunhao.java@gmail.com)
 * @version V1.0, 16/2/26 下午3:26
 */
@Component
public class TextMsgHandler implements MsgHandler<TextMsg> {
    @Override
    public boolean support(MsgType msgType) {
        return msgType == MsgType.text;
    }

    @Override
    public Reply handle(TextMsg msg) {
        TextReply reply = new TextReply();
        reply.createTime = new Date().getTime();
        reply.fromUserName = msg.toUserName;
        reply.toUserName = msg.fromUserName;
        reply.msgType = ReplyType.text;
        reply.content = "Hello! 我是孙昊,回复来自[微信公众号API]";

        return reply;
    }

    @Override
    public Class<TextMsg> getType() {
        return TextMsg.class;
    }
}
